import { list } from '../../../api/group'
Page({
    data: {
        inputValue:'',
        options:[],
        keyword:'',
        pageNum:1,
        pageSize:10
    },
    onLoad(options) {
        this.getGroup()
    },
    keywordUpdate(e){
        this.data.keyword = e.detail.value
        this.setData({
            keyword: this.data.keyword
        })
    },
    handleQueryClear(){
        this.data.keyword = ""
        this.data.options = []
        this.setData({
            keyword:this.data.keyword,
            options:this.data.options
        })
        this.getGroup()
    },
    handleQuery(){
        this.data.options = []
        this.setData({
            options:this.data.options
        })
        this.getGroup()
    },
    getGroup(){
        let params = {
            type:1,
            keyword:this.data.keyword,
            pageNum:this.data.pageNum,
            pageSize:this.data.pageSize
        }
        list(params).then(res =>{
            res.data.data.forEach(item=>{
                this.data.options.push(item)
            })
            this.setData({
                options:this.data.options
            })
        })
    },
    chooseSeller(e){
        let pages = getCurrentPages();
        let prevPage = pages[pages.length-2];
        prevPage.data.group_id = e.currentTarget.dataset.item.id
        prevPage.setData({
            group_name: e.currentTarget.dataset.item.name,
            group_id:e.currentTarget.dataset.item.id,
        });
        wx.navigateBack({
          delta: 1,
        })
    },
    onPullDownRefresh(){
        this.data.pageNum = 1
        this.data.options = []
        this.setData({
            pageNum:this.data.pageNum,
            options:this.data.options
        })
        this.getGroup()
        let settime = setTimeout(()=>{
            wx.stopPullDownRefresh()
            clearTimeout(settime)
        },1000)
    },
    onReachBottom(){
        this.data.pageNum = this.data.pageNum + 1
        this.setData({
            pageNum:this.data.pageNum
        })
        this.getGroup()
    }
})